// GeometryObjectGenerator.cpp: implementation of the GeometryObjectGenerator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GeometryObjectGenerator.h"
#include "SHPoint.h"
#include "dbhandle.h"
#include "dbents.h"
#include "UEEntityOperation.h"
#include "PartPoint.h"
#include "PipeGenerator.h"
#include "NewGeometryObject.h"
#include "JointPart.h"
#include "ModelGenerator.h"
#include "ModelEntityGenerator.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

using namespace JointSystem;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

GeometryObjectGenerator::GeometryObjectGenerator()
{

}

GeometryObjectGenerator::~GeometryObjectGenerator()
{

}

BOOL GeometryObjectGenerator::Visit(SupportHanger& part)
{
/*	SHPoint* pSHpt = new SHPoint;
	ASSERT(pSHpt);

	SupportHangerPoint& pt = part.GetSupportHangerPoint();
	BOOL bResult = pSHpt->Create(pt.Database(), pt.PrjID(), pt.VolumeID(), pt.SupportHangerID(),
		part.BlockName());

	if(!bResult)
		return bResult;

	part.AddObserver(pSHpt);
//	part.SupportHangerObserver(pSHpt);
	pSHpt->SupportHangerOwner(&part);
	part.ModelMatrix(pSHpt->GetSupportHangerPoint().BaseMatrix());
	part.GetSupportHangerPoint().BaseMatrix(pSHpt->GetSupportHangerPoint().BaseMatrix());
	ASSERT(bResult);

	PartManager& theManager = part.GetPartManager();
	PartManager::Iterator* pIterator = theManager.NewIterator();
	ASSERT(pIterator);

	for(pIterator->Begin(); !pIterator->End(); pIterator->Next())
	{
		Part* pPart = pIterator->Get();
		ASSERT(pPart);
		Visit(*pPart);
	}
	delete pIterator;

	return bResult;*/
	return TRUE;
}

BOOL GeometryObjectGenerator::Visit(Part& part)
{
	ASSERT(part.SupportHangerOwner());

	AcDbHandle handle;
	if(part.GetCustomID() == PipeGenerator::PipeID())
	{
		handle = NewPipeEntity(part);
	}
	else
	{
		handle = NewPartEntity(part);
	}
	
	ModelObserver* pOb = NewGeometryObject::Instance()->Generate(part, handle);
	part.SetNotUpdateObserver();
	if(pOb == NULL)
		return FALSE;
	return TRUE;
}

AcDbHandle GeometryObjectGenerator::NewPipeEntity(Part& part)
{
//	SHPoint* pPoint = part.SupportHangerOwner()->SupportHangerObserver();
//	ASSERT(pPoint);

/*	AcDbPoint* pPt = new AcDbPoint(pPoint->basePoint());
	Acad::ErrorStatus es = CUEEntityOperation::AddEntityToDwg(pPt, _T(""), FALSE);
	ASSERT(es == Acad::eOk);
	pPt->getAcDbHandle(handle);

	pPt->close();
*/
	AcDbHandle handle;
	handle.setNull();
	return handle;
}

AcDbHandle GeometryObjectGenerator::NewPartEntity(Part& part)
{
/*	AcDbEntity* pEnt = ModelEntityGenerator::Instance()->Generate(part);
	assert( pEnt );

	ASSERT(part.SupportHangerOwner());
	ASSERT(part.SupportHangerOwner()->SupportHangerObserver());
	pEnt->transformBy(part.ModelMatrix());
	pEnt->transformBy(part.SupportHangerOwner()->SupportHangerObserver()->SHMatrix());
	
	Acad::ErrorStatus es = CUEEntityOperation::AddEntityToDwg(pEnt, _T(""), FALSE);
	ASSERT(es == Acad::eOk);

	pEnt->getAcDbHandle(handle);

	pEnt->close();*/
	AcDbHandle handle;
	handle.setNull();
	return handle;
}